#encoding:utf-8

class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None




def creat_List(l, n):
    l.val = int(input())
    p = l
    for i in range(n - 1):
        node = ListNode(None)
        node.val = int(input())
        p.next = node
        p = p.next

    p.next = None




def traverse(l):
    p = l
    while p:
        print(p.val, ' ', end='')
        p = p.next

    print()



class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        if l1 == None:
            return l2
        if l2 == None:
            return l1

        dummy = ListNode(0)
        p = dummy
        carry = 0
        while l1 and l2:
            p.next = ListNode((l1.val+l2.val + carry)%10)
            carry = (l1.val+l2.val+carry)//10
            l1 = l1.next
            l2 = l2.next
            p = p.next

        if l2:
            while l2:
                p.next = ListNode((l2.val + carry) % 10)
                carry = (l2.val + carry) // 10
                l2 = l2.next
                p = p.next

        if l1:
            while l1:
                p.next = ListNode((l1.val + carry) % 10)
                carry = (l1.val + carry) // 10
                l2 = l1.next
                p = p.next

        if carry == 1:
            p.next = ListNode(1)

        return dummy
l1 = ListNode(None)
creat_List(l1,3)
traverse(l1)

l2 = ListNode(None)
creat_List(l2,3)
traverse(l2)
dc = Solution()
traverse(dc.addTwoNumbers(l1,l2))